package collection.exercise;

import java.util.LinkedHashSet;
import java.util.Objects;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-02-12
 * Time:2:23
 */
public class Exercise6 {
    public static void main(String[] args) {
        LinkedHashSet<Car> cars = new LinkedHashSet<>();
        cars.add(new Car("aodi",10000));
        cars.add(new Car("aodi",30000));
        cars.add(new Car("falali",100000));
        cars.add(new Car("benchi",40000));
        cars.add(new Car("aodi",10000));
        System.out.println(cars);
    }
}
@SuppressWarnings("all")
class Car {
    private String name;
    private double price;

    public Car(String name, double price) {
        this.name = name;
        this.price = price;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Car car = (Car) o;
        return Double.compare(price, car.price) == 0 && Objects.equals(name, car.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, price);
    }

    @Override
    public String toString() {
        return "Car{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}'+"\n";
    }
}